<?php
namespace Managers;
use \Site\Phones as PhonesEntity;

class Phones extends BaseManager{
    public function getAll(){
        return $this->getEntityManager()
                ->createQueryBuilder()
                ->select('n')
                ->from('Site\Phones', 'n')
                ->orderBy('n.id', '')
                ->getQuery()
                ->getResult();
    }

    public function getOne($id){
       try{
            return $this->getEntityManager()
                ->createQueryBuilder()
                ->select('n')
                ->from('Site\Phones', 'n')
                ->where('n.user = :id')
                ->getQuery()
                ->setParameters(array('id'=>$id))
                ->getResult();
        }catch (\Doctrine\ORM\NoResultException $e){
           return NULL;
        }
    }

     public function AddPhone($array){
        $entity = new PhonesEntity();
        $entity->setUser($array['id']);
        $entity->setKod($array['kod']);
        $entity->setNumber($array['number']);
        $entity->setType($array['type_phone']);
        $em = $this->getEntityManager();
        $em->persist($entity);
        $em->flush();
     }

}
